//使用mobx
import {getToken, http, removeToken, setToken} from '@/utils'
import {makeAutoObservable} from "mobx";

class LoginStore {
    token = getToken() || ''

    constructor() {
        //响应式
        makeAutoObservable(this)
    }

    getToken = async ({mobile, code}) => {
        //调用登录接口
        const res = await http.post('/authorizations', {mobile, code})
        // console.log(res)
        //存入token
        this.token = res.data.token
        //存入localStorage
        setToken(this.token)
    }
    //退出逻辑
    loginOut = () => {
        this.token = ''
        removeToken()
    }
}

export default LoginStore